home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / Reversed fades ƒ / Four centered fade reversed.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-12  |  3.2 KB  |  107 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Four centered fade reversed.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg timing.h"
  30.  
  31. #define CorrectTime 6
  32. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  33. #define theWindowWidth (boundsRect.right-boundsRect.left)
  34.  
  35. pascal short FourCenteredFadeReversed(Rect boundsRect, Pattern *thePattern);
  36.  
  37. /* Really, this only uses one region and one CopyBits per round.  Regions don't
  38.    have to be continuous.  On each axis, on each side of the center of the screen,
  39.    there are two parts of the region which move from the corners to the center. */
  40.    
  41. pascal short FourCenteredFadeReversed(Rect boundsRect, Pattern *thePattern)
  42. {
  43.     RgnHandle    curregion, boundsRgn, sectrgn;
  44.     int            cx,cy,lastx,lasty;
  45.     int            BlockSize, VBlockSize;
  46.     
  47.     cx = boundsRect.left + theWindowWidth / 2;
  48.     cy = boundsRect.top + theWindowHeight / 2;
  49.     BlockSize=theWindowWidth/50;
  50.     VBlockSize=theWindowHeight/50;
  51.  
  52.     boundsRgn=NewRgn();
  53.     SetRectRgn(boundsRgn, boundsRect.left, boundsRect.top, boundsRect.right, boundsRect.bottom);
  54.     sectrgn=NewRgn();
  55.     
  56.     curregion=NewRgn();
  57.     
  58.     lasty=theWindowHeight/2;
  59.     lastx=theWindowWidth/2;
  60.     do
  61.     {
  62.         StartTiming();
  63.         SetEmptyRgn(curregion);
  64.         MoveTo(cx,cy);
  65.         OpenRgn();              /* much much faster than 8 regions/CopyBits */
  66.             LineTo(cx-lastx,boundsRect.top);
  67.             Line(-BlockSize,0);
  68.             LineTo(cx+lastx+BlockSize,boundsRect.bottom);
  69.             Line(-BlockSize,0);
  70.             LineTo(cx,cy);
  71.             
  72.             LineTo(cx+lastx,boundsRect.top);
  73.             Line(BlockSize,0);
  74.             LineTo(cx-lastx-BlockSize,boundsRect.bottom);
  75.             Line(BlockSize,0);
  76.             LineTo(cx,cy);
  77.             
  78.             LineTo(boundsRect.right,cy-lasty);
  79.             Line(0,-VBlockSize);
  80.             LineTo(boundsRect.left,cy+lasty+VBlockSize);
  81.             Line(0,-VBlockSize);
  82.             LineTo(cx,cy);
  83.             
  84.             LineTo(boundsRect.right,cy+lasty);
  85.             Line(0,VBlockSize);
  86.             LineTo(boundsRect.left,cy-lasty-VBlockSize);
  87.             Line(0,VBlockSize);
  88.             LineTo(cx,cy);
  89.         CloseRgn(curregion);
  90.  
  91.         SectRgn(curregion, boundsRgn, sectrgn);
  92.         FillRgn(sectrgn, *thePattern);
  93.         lastx-=BlockSize;
  94.         lasty-=VBlockSize;
  95.         TimeCorrection(CorrectTime);
  96.     }
  97.     while (lastx>boundsRect.left);
  98.  
  99.     FillRect(&boundsRect, *thePattern);        /* in case we miss a few pixels */
  100.     
  101.     DisposeRgn(curregion);
  102.     DisposeRgn(boundsRgn);
  103.     DisposeRgn(sectrgn);
  104.     
  105.     return 0;
  106. }
  107.